Allow FunctionResultContent pass-through when CallId matches#7229
Allow FunctionResultContent pass-through when CallId matches#7229stephentoub merged 8 commits intomainfrom
Conversation
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
|
@copilot also unseal FunctionCallContent and FunctionResultContent and add tests validating that an AIFunction can return a FunctionResultContent-derived type and that instance is what's propagated to the IChatClient wrapped by the FunctionInvokingChatClient. |
…e propagation test Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
…nt test Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
Done in 790f979. Unsealed both |
test/Libraries/Microsoft.Extensions.AI.Tests/ChatCompletion/FunctionInvokingChatClientTests.cs
Show resolved
Hide resolved
…ount Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
test/Libraries/Microsoft.Extensions.AI.Tests/ChatCompletion/FunctionInvokingChatClientTests.cs
Outdated
Show resolved
Hide resolved
test/Libraries/Microsoft.Extensions.AI.Tests/ChatCompletion/FunctionInvokingChatClientTests.cs
Outdated
Show resolved
Hide resolved
…onResultContent tests Co-authored-by: jozkee <16040868+jozkee@users.noreply.github.com>
FunctionInvokingChatClient.CreateResponseMessagesshould reuseFunctionResultContentreturned by the function if theCallIdmatchesFunctionInvokingChatClient.csat line 1230FunctionCallContentandFunctionResultContentclassesFunctionResultContenttype is propagated to the innerIChatClientSummary
This PR modifies
FunctionInvokingChatClient.CreateResponseMessagesto check if the function result is already aFunctionResultContentwith a matchingCallId. If so, it uses that instance directly instead of wrapping it in a newFunctionResultContent. This gives the AIFunction flexibility to create its own FunctionResultContent configured however it wants.Additionally, this PR unseals
FunctionCallContentandFunctionResultContentclasses to allow derivation.Changes:
FunctionInvokingChatClient.CreateFunctionResultContentmethod to check if the result is aFunctionResultContentwith a matchingCallIdand return it directlyFunctionCallContentandFunctionResultContentclasses to allow derivationFunctionReturningFunctionResultContentWithMatchingCallId_UsesItDirectly: Verifies that when a function returns a FunctionResultContent with matching CallId, it is used directly (same reference)FunctionReturningFunctionResultContentWithMismatchedCallId_WrapsIt: Verifies that when a function returns a FunctionResultContent with mismatched CallId, it is wrapped in a new FunctionResultContent (with the inner one reference-equal)FunctionReturningDerivedFunctionResultContent_PropagatesInstanceToInnerClient: Verifies that a derived FunctionResultContent type is properly propagated to the wrapped IChatClient and is the only one in the tool message (same reference)Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.
Microsoft Reviewers: Open in CodeFlow